package nickthissen.iracing.common;

import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;

import org.apache.http.cookie.Cookie;

import java.util.List;

import nickthissen.iracing.networking.NetworkMethod;

/**
 * Created by nthissen on 04/06/13.
 */
public class WebViewUtil
{
    public static void syncCookies(WebView webview)
    {
        // Sync authentication cookies with WebView
        CookieSyncManager.createInstance(webview.getContext());
        CookieManager manager = CookieManager.getInstance();

        List<Cookie> cookies = NetworkMethod.getCookieStore().getCookies();
        for (Cookie c : cookies)
        {
            manager.setCookie(c.getDomain(), c.getName() + "=" + c.getValue());
            CookieSyncManager.getInstance().sync();
        }
    }
}
